
#include <socket/socket_common.hpp>

namespace Tux { namespace Socket
{
    char const* DomainType::ToString(Enum e)
    {
        switch (e)
        {
        case LOCAL: return "LOCAL";
        case IPv4:  return "IPv4";
        case IPv6:  return "IPv6";
        default:    return "???";
        }
    }

    char const* SocketType::ToString(Enum e)
    {
        switch (e)
        {
        case DATAGRAM:  return "DATAGRAM";
        case STREAM:    return "STREAM";
        default:        return "???";
        }
    }

    LocalDomainTraits::SocketAddress 
    LocalDomainTraits::CreateSocketAddress(char const* name)
    {
        // TODO: validate length
        SocketAddress addr;
        memset(&addr, 0, sizeof(SocketAddress));
        addr.sun_family = AF_UNIX;
        strcpy(addr.sun_path + 1, name);
        return addr;
    }

    socklen_t LocalDomainTraits::SizeOfSocketAddress(SocketAddress const& address)
    {
        (void)address;
        return sizeof(SocketAddress);
    }
}}

